import { Space, Button,message } from 'antd';
import { useState } from 'react'
import OrderdetailsDel from '../child/OrderdetailsDel';
import { confirmOrderById ,closeOrderById} from '../../../../api/OrderApi'
// import { useNavigate } from 'react-router-dom'

export default function OrderBtn(props: any) {
    const [isModalOpen, setIsModalOpen] = useState(false);
    // const navigate = useNavigate()

    console.log('props.value---btns',props.value);
    
    // 确认订单
    const confirmOrder = () => {
        console.log('确认订单');
        confirmOrderById({
            orderId:props.value.orderId
        }).then(res=>{
            console.log('确认订单res',res);
            message.success('确认订单成功')
        }).catch(err=>{
            console.log('err345',err);
            message.success('服务器错误')
        })
        // message.success('已确认订单')

    }
    // 修改订单
    const updateOrder = () => {
        console.log('修改订单');
        setIsModalOpen(true)
        // navigate('/home/order/OrderdetailsDel')
    }
    // 关闭订单
    const closeOrder = () => {
        console.log('关闭订单');
        console.log('props.value.orderId',props.value.orderId);
        closeOrderById({
            orderId:props.value.orderId
        }).then(res=>{
            console.log('关闭订单res',res);
            message.success('关闭订单成功')
        }).catch(err=>{
            console.log('err345',err);
            message.success('服务器错误')
        })
    }
    // 关闭编辑框
    const close =()=>{
        setIsModalOpen(false)
    }
    return (
        <div>
            <Space className='btns'>
                <Button type='primary' onClick={confirmOrder}>确认订单</Button>
                <Button danger type="primary" onClick={updateOrder}>修改订单</Button>
                <Button onClick={closeOrder}>关闭订单</Button>
            </Space>
    {/* // 编辑订单的弹框 */}
            <OrderdetailsDel isModalOpen={isModalOpen} close={close } params={props.value}></OrderdetailsDel>
        </div>
    )
}